package org.hot100_3;

import java.util.List;

public class leetcode21 {
    public static ListNode mergeTwoLists(ListNode list1, ListNode list2) {

        ListNode dummy= new ListNode(-1);

        ListNode item = dummy;

        while (list1!=null && list2!=null){
            if (list1.val<list2.val){
                item.next=list1;
                list1=list1.next;
            }else {
                item.next=list2;
                list2=list2.next;
            }
            item=item.next;
        }

        if ( list2!=null){
            item.next=list2;
        }

        if ( list1!=null){
            item.next=list1;
        }

        return dummy.next;
    }

    public static void main(String[] args) {
        ListNode node = new ListNode(1,new ListNode(2,new ListNode(4,null)));
        ListNode node1 = new ListNode(1,new ListNode(3,new ListNode(4,null)));

        mergeTwoLists(node,node1);
    }
}
